package ar.edu.caece.compiler.grammar.factories;

import ar.edu.caece.compiler.error.ParsingException;
import ar.edu.caece.compiler.grammar.AbstractTokenVisitorFactory;
import ar.edu.caece.compiler.grammar.Recognizer;
import ar.edu.caece.compiler.grammar.TokenRecognizer;
import ar.edu.caece.compiler.grammar.TokenVisitor;

import ar.edu.caece.compiler.grammar.attributes.StringAttribute;
import ar.edu.caece.compiler.grammar.nonterminals.REL2;
import ar.edu.caece.compiler.grammar.terminals.DistintoNaturalToken;

public class REL2Factory extends AbstractTokenVisitorFactory {

	private static REL2Factory INSTANCE;
	
	public static REL2Factory getInstance() {
		if(INSTANCE==null) INSTANCE = new REL2Factory();
		return INSTANCE;
	}
	
	private REL2Factory() {
		
	}
	
	@Override
	public TokenVisitor makeChainedVisitor(
			final TokenVisitor siguiente) throws Exception {
		return new DistintoNaturalToken.DistintoNaturalChainVisitor(siguiente) {
			
			@Override
			public Recognizer distintoNaturalCase(DistintoNaturalToken llamador) {
				REL2 rel2 = new REL2(llamador);
				rel2.addAttribute("op",new StringAttribute("DISTINTO"));

				return rel2;			}
		};
	
	}
	@Override
	public TokenVisitor makeVisitor() throws Exception {
		return new DistintoNaturalToken.DistintoNaturalTokenVisitor() {
			
			@Override
			public Recognizer defaultCase(TokenRecognizer llamador) throws Exception {
				throw new ParsingException("Error de parsing.",REL2.class,llamador);
			}
			
			@Override
			public Recognizer distintoNaturalCase(DistintoNaturalToken llamador) {
				REL2 rel2 = new REL2(llamador);
				rel2.addAttribute("op",new StringAttribute("DISTINTO"));

				return rel2;
			}
		};
	}
	
	
}
